#include "Firmware.h"

DArray* Filter(DArray Input)
{
	DArray* result = &Input;

	uint i = 0;
	uint j = 0;
	uint k = 0;
	sbyte ex = 0;
	result->size = Input.size;

	for(i = 0; i < Input.size; i++)
	{
		if(Input.data[i] > 0x75 && Input.data[i] < 0x80 && i < Input.size - 1)
			k++;
		else
		{
			if(k > 100)
			{
				for(j = 1; j <= k; j++)
					Input.data[i - j] = 0;

				result->size -= k;
			}
			k = 0;

			if(Input.data[i] != ex)
				ex = Input.data[i];
			else
			{
				Input.data[i] = 0;
				result->size--;
			}
		}
	}

	result->data = (bytep) malloc(result->size);
	j = 0;

	for(i = 0; i < Input.size; i++)
	{
		if(Input.data[i] != 0)
			result->data[j++] = Input.data[i];
	}

	return result;
}